<?php
/**
 * 攀枝花his新接口
 * http://127.0.0.1/index.php?g=Pzhrs&m=HisApi&a=K0003
 */
namespace Pzhrs\Controller;

use Think\Exception;

class HisApiController
{
    //his数据转发地址
    //const HIS_URL = 'http://118.89.34.25:123/his/';
    const HIS_URL = 'http://127.0.0.1:81/his/';
    //万达webservice地址
    //const WEBSERVICE_URL = 'http://17d38h3278.imwork.net/PzhDataExchangeClient/webservice/commonService?wsdl';
//    const WEBSERVICE_URL = 'http://172.16.0.2:20365/PzhDataExchangeClient/webservice/commonService?wsdl'; // 测试环境
    const WEBSERVICE_URL = 'http://172.16.0.2:20351/DataExchangeClient/webservice/commonService?wsdl';
    // 调用方私钥
    const WEBSERVICE_PRIVATE_KEY = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAOyeVx9P44VO6i5PuBZ1KDgqQqyl7A+A7s1nmDCgrmxWiic6FdhnIysIC3pUUYkzeDAufnnqAVb4uoA7WdcmGp4gCgpQ/dFhI0ZorSL2VWoR6ZjKgswiiBo1JEMsFA9dl++3V+qKNm9b6A2IaeDSJE/NM/dYSkWwrp/RyCaQTR1hAgMBAAECgYEA3cTKAx7tL9R2yFEPSH0l5P4233njdeRx7TJbAbiXwhKaCYn3T4va+knf+BdvFBiZXQ82my0ndExLAESgP3YHGr9bRLPDx0ssQhVO7+kclp5beL6V1x47wR/44P72w9bKhMBkns9HvtSLM4GDx5V58P72mxlPgps3dD5z6X8DcAECQQD/w0OkvYr808DAd3yUFQ8OsaI3OdxRnQQi0R7aOydt832Lyb+Ybr1Dcmr9ODVpf8vETuAOD5NixYBNSuaj1RHxAkEA7NaHqRTiXsLUian96Ai9/iRUF1M/wNXiJHzhzZScIGUucLv7pjMhrGO65adlSQcuYBX+wCYswhlWgdrGNpFScQJAfh+Odei6Z18MyFyj5GpWGIrkUZOI3/4sEfdJ3ZgaI5BVMt/0SXkif+YmeGSFglbw5wd2Wbi4l5aJZJQxFE14IQJBAIFLdPAniJV3A5TMCuNbsm1F4+p/9jQOD9EfpB4ZXUqKMlo1JeLL0zxLjcLGKhM+KmEmYNcBgDnOn11w0/kCSOECQQCbsAHHRxknaOMRl0VX6S8esBQFvQGlRVng8Mkfwe5pcTuk6JGSfsD1iVjWUfxJY3jwuezoHIdwldaq0pf5df3B";
    //密码加密公钥
    const PASSWORD_PUBLIC_KEY = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlIUD062CGS1oNj6pAKRMX0Tqu5d1vCzaqpOaiHWF6jbjnEYTkYaJ59ma/I4auCnfbsz49lCfNyDZvWHpwIpgLl8OgOtov3dnMrVNEWf3XQ2VoHB+CCDCZvMiSvi7WewpyqC7HwZvwwDrhC5kvTA/ei8Nk2GwqbUuQ4Gveth0txQIDAQAB';
    //应用渠道代码
    const SYSCHANNEL_CODE = '002';
    //应用渠道名称
    const SYSCHANNEL_NAME = '03';
    //第三方ID前缀
    const TCYL_KEY = 'tcyl_';
    //YYJK调医院接口0 YHJK调银海接口1  ZFMMZTCX支付密码验证2   ZFMMXG支付密码修改3 ZFMMYZ支付密码验证 4 DZSBKZTCX 签发查询 5,6付款码生成,7药店订单查询,8微信支付异步通知,9医保正式结算,10药店订单状态查询
    const BUS_CODE = ['YYJK', 'YHJK', 'ZFMMZTCX', 'ZFMMXG', 'ZFMMYZ', 'DZSBKZTCX', 'EWMSC', 'YDDDCX', 'ZFYBTZ', 'YDYBJS', 'YDZDCX'];
    //I00011  I90007(支付密码验证和支付密码修改)
    const SYS_CODE = ['I00011', 'I90007', 'I01020'];
    //医保项目编码
    const INSURANCE_NO = 'XC999999-2';
	//电子社保卡签发ak
    const CARD_AK = '4c13aa0d08ac4d9b9e955c9b78a3d135';
    //电子社保卡签发sk
    const CARD_SK = 'K3OzQQMhoAaeDQqVuLkx9ysdtN0=';
    //电子社保卡签发dk数字密钥
    const CARD_DK = 'oe28gpwtu3dhpq5y';
    //电子社保卡签发channelNo渠道号
    const CARD_CHANNEL_NO = '5104008001';
    //电子社保卡签发发卡地区行政区划代码
    const CARD_LOCAL_CODE = '510400';
    //电子社保卡签发发测式地址前缀
    //const CARD_WEB_URL = 'https://test-ssc.mohrss.gov.cn/portal/#';
	//电子社保卡签发发正式地址前缀
    const CARD_WEB_URL = 'https://ssc.mohrss.gov.cn/portal/#';
    //测试环境地址(通过金保专网访问) ：
    //const JING_BAO_URL = 'http://172.16.0.2:20368/ecardapi';
    //生产环境地址(通过金保专网访问)：
    const JING_BAO_URL = 'http://172.16.0.2:20367/ecardapi';
    //智能管服系统key
    const HIS_CHAT_KEY = 'UfO+eoF9fSbEVcGql5YjZp3y9fuM57kzmwCLtn2AQgE=';
    const HIS_CHAT_URL = 'http://172.16.0.2:20383/api/archive/retire-and-unauth?p=';

    const ENV_DEVELOPMENT = "development";

    const ENV_PRODUCTION = "production";

    const ENVIRONMENT = self::ENV_PRODUCTION; // 开发环境为 development; 发布环境为 production

    public static $environmentConfig = [
        // 开发环境
        self::ENV_DEVELOPMENT => [
            // 测试万达webservice地址
            'web_service_url' => 'http://172.16.0.2:20365/PzhDataExchangeClient/webservice/commonService?wsdl',
            // 万达服务私钥
            'web_service_private_key' => '',
            // 密码加密公钥
            'password_public_key' => '',
            // 测试环境电子社保卡服务地址
            'jin_bao_url' => 'http://172.16.0.2:20368/ecardapi',
            // 测试环境智能管服系统KEY
            'his_chat_key' => '',
            // 智能管服系统服务地址
            'his_card_url' => '',
            // 电子社保卡签发测试地址
            'card_web_url' => 'https://test-ssc.mohrss.gov.cn/portal/#',
            // 电子社保卡签发sk
            'card_sk' => '',
            // 电子社保卡签发Ak
            'card_ak' => '',
            // his 数据转发
            'his_url' => 'http://127.0.0.1:81/his/',
        ],
        // 生产环境
        self::ENV_PRODUCTION => [
            // 万达webservice地址
            'web_service_url' => 'http://172.16.0.2:20351/DataExchangeClient/webservice/commonService?wsdl',
            // 万达服务私钥
            'web_service_private_key' => 'MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAOyeVx9P44VO6i5PuBZ1KDgqQqyl7A+A7s1nmDCgrmxWiic6FdhnIysIC3pUUYkzeDAufnnqAVb4uoA7WdcmGp4gCgpQ/dFhI0ZorSL2VWoR6ZjKgswiiBo1JEMsFA9dl++3V+qKNm9b6A2IaeDSJE/NM/dYSkWwrp/RyCaQTR1hAgMBAAECgYEA3cTKAx7tL9R2yFEPSH0l5P4233njdeRx7TJbAbiXwhKaCYn3T4va+knf+BdvFBiZXQ82my0ndExLAESgP3YHGr9bRLPDx0ssQhVO7+kclp5beL6V1x47wR/44P72w9bKhMBkns9HvtSLM4GDx5V58P72mxlPgps3dD5z6X8DcAECQQD/w0OkvYr808DAd3yUFQ8OsaI3OdxRnQQi0R7aOydt832Lyb+Ybr1Dcmr9ODVpf8vETuAOD5NixYBNSuaj1RHxAkEA7NaHqRTiXsLUian96Ai9/iRUF1M/wNXiJHzhzZScIGUucLv7pjMhrGO65adlSQcuYBX+wCYswhlWgdrGNpFScQJAfh+Odei6Z18MyFyj5GpWGIrkUZOI3/4sEfdJ3ZgaI5BVMt/0SXkif+YmeGSFglbw5wd2Wbi4l5aJZJQxFE14IQJBAIFLdPAniJV3A5TMCuNbsm1F4+p/9jQOD9EfpB4ZXUqKMlo1JeLL0zxLjcLGKhM+KmEmYNcBgDnOn11w0/kCSOECQQCbsAHHRxknaOMRl0VX6S8esBQFvQGlRVng8Mkfwe5pcTuk6JGSfsD1iVjWUfxJY3jwuezoHIdwldaq0pf5df3B',
            // 密码加密公钥
            'password_public_key' => 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlIUD062CGS1oNj6pAKRMX0Tqu5d1vCzaqpOaiHWF6jbjnEYTkYaJ59ma/I4auCnfbsz49lCfNyDZvWHpwIpgLl8OgOtov3dnMrVNEWf3XQ2VoHB+CCDCZvMiSvi7WewpyqC7HwZvwwDrhC5kvTA/ei8Nk2GwqbUuQ4Gveth0txQIDAQAB',
            // 环境电子社保卡服务地址
            'jin_bao_url' => 'http://172.16.0.2:20367/ecardapi',
            // 智能管服系统KEY
            'his_chat_key' => 'UfO+eoF9fSbEVcGql5YjZp3y9fuM57kzmwCLtn2AQgE=',
            // 智能管服系统服务地址
            'his_card_url' => 'http://172.16.0.2:20383/api/archive/retire-and-unauth?p=',
            // 电子社保卡签发测试地址
            'card_web_url' => 'https://ssc.mohrss.gov.cn/portal/#',
            // 电子社保卡签发sk
            'card_sk' => 'K3OzQQMhoAaeDQqVuLkx9ysdtN0=',
            // 电子社保卡签发Ak
            'card_ak' => '4c13aa0d08ac4d9b9e955c9b78a3d135',
            // his 数据转发
            'his_url' => 'http://127.0.0.1:81/his/',
        ]
    ];

    /**
     * 退休人员资格认证通知
     */
    public function retireeNotice() {
        //身份证号
        $id = $_POST['mi_card_no'];
        //$id = '510402195909210024';
        //用户操作（1-社保查询、2-社会保障卡查询、3-线上服务、4-电子社保卡 …）
        $operation = 3;
        $requestParams = '{"from":"1","id":"'.$id.'","operation":"'.$operation.'"}';
        $dataArray = [
            'jsonStr' => $requestParams,
//            'key' => self::HIS_CHAT_KEY,
            'key' => self::$environmentConfig[self::ENVIRONMENT]['his_chat_key']
        ];

        $this->logFile('chat', 'res', json_encode($dataArray, JSON_UNESCAPED_UNICODE));
        $response = $this->curlPost(self::$environmentConfig[self::ENVIRONMENT]['his_url'] . 'chat', $dataArray);
        $this->logFile('chat', 'res', $response);
        if ($response == false) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = '接口地址404';
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseJson = json_decode($response);
        if ($responseJson->resultcode == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $responseJson->resultmessage;
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
//        $url = self::HIS_CHAT_URL . $responseJson->resultmessage;
        $url = self::$environmentConfig[self::ENVIRONMENT]['his_chat_url'] . $responseJson->resultmessage;
        $res = $this->curl_post($url , $data=array());
        echo json_encode($res, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 智能管服加密串获取
     */
    public function chat() {
        //姓名
        $name = $_POST['user_name'];
        //身份证号
        $id = $_POST['mi_card_no'];
        //社保卡号
        $card = $_POST['social_card_no'];
        //手机号
        $tel = $_POST['phone'];
        $requestParams = '{"from":"3","id":null,"tel":null,"name":null,"age":null,"sex":null,"type":null,"card":null,"company":null,"address":null}';
        if ($name != '' && $id !='' && $card != '' && $tel != '') {
            $requestParams = '{"from":"3","id":"'.$id.'","tel":"'.$tel.'","name":"'.$name.'","age":null,"sex":null,"type":null,"card":"'.$card.'","company":null,"address":null}';
        }
        $dataArray = [
            'jsonStr' => $requestParams,
//            'key' => self::HIS_CHAT_KEY,
            'key' => self::$environmentConfig[self::ENVIRONMENT]['his_chat_key']
        ];

        $this->logFile('chat', 'res', json_encode($dataArray, JSON_UNESCAPED_UNICODE));
        $response = $this->curlPost(self::$environmentConfig[self::ENVIRONMENT]['his_url'] . 'chat', $dataArray);
        $this->logFile('chat', 'res', $response);
        if ($response == false) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = '接口地址404';
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseJson = json_decode($response);
        if ($responseJson->resultcode == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $responseJson->resultmessage;
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = $responseJson->resultmessage;
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    //付款码生成
    public function ewmsc() {
        $xmlArray = Array();
        $actionName = 'EWMSC';

        //身份证号码
        $xmlArray['idCard'] = $_POST['user_card_no'];
        $xmlDataArray['data'] = $this->array_to_xml_two($xmlArray);

        $dataXml = '<?xml version="1.0" encoding="UTF-8"?>'.$this->array_to_xml_two($xmlDataArray);
        $this->logFile($actionName, 'xml', $dataXml);
        $response = $this->hisMiddleware($dataXml, 6, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if ($response['resultcode'] != 1) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $response['resultmessage'];
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = '成功';
        $responseArray['item'] = $response;
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    //药店订单查询
    public function ydddcx() {
        $xmlArray = Array();
        $actionName = 'YDDDCX';

        //身份证号码
        $xmlArray['idCard'] = $_POST['user_card_no'];
        $xmlArray['name'] = $_POST['user_name'];
        $xmlArray['payCode'] = $_POST['pay_code'];

        $xmlDataArray['data'] = $this->array_to_xml_two($xmlArray);
        $dataXml = '<?xml version="1.0" encoding="UTF-8"?>'.$this->array_to_xml_two($xmlDataArray);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 7, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if ($response['resultcode'] != 1) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $response['resultmessage'];
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = '成功';
        $responseArray['item'] = $response;
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    //药店订单查询
    public function zfybtz() {
        $xmlArray = Array();
        $actionName = 'ZFYBTZ';

        //智慧医保平台订单号
        $xmlArray['busiorderno'] = $_POST['his_order_no'];
        //第三方订单号
        $xmlArray['thirdOrder'] = $_POST['out_trade_no'];
        //机构订单号
        $xmlArray['misordnum'] = $_POST['miss_order_no'];
        //现金支付流水号
        $xmlArray['cashpayOrder'] = $_POST['out_trade_no'];
        //订单总金额
        $xmlArray['totalamt'] = $_POST['price_sum'];
        //现金支付金额
        $xmlArray['cashpay'] = $_POST['price_cash'];
        //折扣金额
        $xmlArray['zkje'] = $_POST['price_discount'];
        //现金支付方式
        $xmlArray['paymode'] = 2;
        //支付完成时间
        $xmlArray['paytime'] = date('Y-m-d H:i:s', time());

        $xmlDataArray['data'] = $this->array_to_xml_two($xmlArray);
        $dataXml = '<?xml version="1.0" encoding="UTF-8"?>'.$this->array_to_xml_two($xmlDataArray);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 8, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if ($response['resultcode'] != 1) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $response['resultmessage'];
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = '成功';
        $responseArray['item'] = $response;
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    //3.4.1.医保正式结算-YBZSJS
    public function ybzsjs() {
        $xmlArray = Array();
        $actionName = 'YDYBJS';

        //智慧医保平台订单号
        $xmlArray['busiorderno'] = $_POST['his_order_no'];
        //第三方订单号
        $xmlArray['thirdOrder'] = $_POST['out_trade_no'];
        //机构订单号
        $xmlArray['insordnum'] = $_POST['miss_order_no'];
        //订单总金额
        $xmlArray['totalamt'] = $_POST['price_sum'];
        //医保支付密码
        $xmlArray['scardpwd'] = $this->passwordSubstr($_POST['password']);
        //个人账户支付金额
        $xmlArray['yka065'] = $_POST['price_insurance_fund'];
        //社保基金支付
        $xmlArray['yka107'] = 0;
        //折扣金额
        $xmlArray['zkje'] = $_POST['price_discount'];
        //优惠金额
        //$xmlArray['yf'] = $_POST['price_discount'];
        $xmlArray['appid'] = 'wx7fb1b49ba0572136';
        //来源
        $xmlArray['ly'] = '微信公众号';

        $xmlDataArray['data'] = $this->array_to_xml_two($xmlArray);
        $dataXml = '<?xml version="1.0" encoding="UTF-8"?>'.$this->array_to_xml_two($xmlDataArray);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 9, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if ($response['resultcode'] != 1) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $response['resultmessage'];
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = '成功';
        $responseArray['item'] = $response;
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    //3.4.3.药店账单查询-YDZDCX
    public function ydddztcx() {
        $xmlArray = Array();
        $actionName = 'YDZDCX';

        //开始日期
        $xmlArray['startTime'] = $_POST['start_time'];
        //结束日期
        $xmlArray['endTime'] = $_POST['end_time'];
        //智慧医保平台订单号
        $xmlArray['busiorderno'] = $_POST['his_order_no'];
        $xmlArray['supercode'] = $_POST['supercode'];

        $xmlDataArray['data'] = $this->array_to_xml_two($xmlArray);
        $dataXml = '<?xml version="1.0" encoding="UTF-8"?>'.$this->array_to_xml_two($xmlDataArray);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 10, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if ($response['resultcode'] != 1) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $response['resultmessage'];
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = '成功';
        $responseArray['item'] = $response;
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

//    function auth(){
//        //channelNo渠道号
//        $dataArray['channelNo'] = self::CARD_CHANNEL_NO;
//        //签发号
//        $dataArray['signNo'] = 'D65869F31145E507AFB3FF3F03046C6E';
//        //操作验证串
//        $dataArray['busiSeq'] = 'abc';
//
////        $url = self::JING_BAO_URL.'/ecard/v1/auth';
//        $url = self::$environmentConfig[self::ENVIRONMENT]['jin_bao_url'] . '/ecard/v1/auth';
//        $response = $this->http_post_json($url, json_encode($dataArray));
//        if ($response[0] != 200) {
//            $responseArray['resultcode'] = 0;
//            $responseArray['resultmessage'] = '金保';
//            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
//        }
//        $response = json_decode($response[1]);
//        if ($response->msgCode != '000000') {
//            $responseArray['resultcode'] = 0;
//            $responseArray['resultmessage'] = $response->msg;
//            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
//        }
//        dump($response->result);die;
//        $responseArray['resultcode'] = 1;
//        $responseArray['resultmessage'] = '成功';
//        $responseArray['item'] = $response->result;
//        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
//    }

    /**
     * 电子社保卡二维码认证
     */
//    function authQrcode(){
//        //二维码动态码
//        $dataArray['qrCode'] = '5104008001908533293569';
//        //业务类型(01业务查询 ,02 缴费支付,03其他)
//        $dataArray['busiType'] = '01';
//        //每次请求唯一id
//        $dataArray['requestId'] = time();
//
////        $url = self::JING_BAO_URL.'/ecard/v1/qrcode/v2/valid';
//        $url = self::$environmentConfig[self::ENVIRONMENT]['jin_bao_url'] . '/ecard/v1/qrcode/v2/valid';
//        $response = $this->http_post_json($url, json_encode($dataArray));
//        if ($response[0] != 200) {
//            $responseArray['resultcode'] = 0;
//            $responseArray['resultmessage'] = '金保系统网络异常';
//            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
//        }
//        $response = json_decode($response[1]);
//        if ($response->msgCode != '000000') {
//            $responseArray['resultcode'] = 0;
//            $responseArray['resultmessage'] = '金保系统'.$response->msg;
//            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
//        }
//        dump($response->result);die;
//        $responseArray['resultcode'] = 1;
//        $responseArray['resultmessage'] = '成功';
//        $responseArray['item'] = $response->result;
//        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
//    }

    function http_post_json($url, $jsonStr){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json; charset=utf-8',
                'Content-Length: ' . strlen($jsonStr)
            )
        );
        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        return array($httpCode, $response);
    }

    /**
     * 医院信息查询
     */
    public function HIS021() {
        $aa = '{"resultcode":1,"resultmessage":"success","item":{"aac001":"0000978692","aac002":"510402198705080014","aac003":"李偲涵","aab004":"100010攀钢集团有限公司","akc021":"11","ykc117":"00","ykc194":"2035.38","yac136":"0","aaz500":"DA4565421","aab301":"510400","ykc008":"0","datarow":[]}}';
        echo json_encode(json_decode($aa));die;
    }

    /**
     * 科室信息查询(HIS001)
     */
    public function HIS001() {
        $xmlArray = Array();
        $actionName = 'HIS001';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //科室代码(选填)
        $xmlArray['deptcode'] = $_POST['deptcode'] == 0 ? '' : $_POST['deptcode'];
        //交易号
        $xmlArray['functionid'] = $actionName;

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 医师信息查询(HIS002)
     */
    public function HIS002() {
        $xmlArray = Array();
        $actionName = 'HIS002';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //科室代码(选填)
        $xmlArray['deptcode']= $_POST['deptcode'] == 0 ? '' : $_POST['deptcode'];
        //医生代码(选填)
        $xmlArray['doctorcode'] = $_POST['doctorcode'] == 0 ? '' : $_POST['doctorcode'];
        //交易号
        $xmlArray['functionid'] = $actionName;

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 号源信息查询(HIS003)
     */
    public function HIS003() {
        $xmlArray = Array();
        $actionName = 'HIS003';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //科室代码(选填)
        $xmlArray['deptcode']= $_POST['deptcode'] == 0 ? '' : $_POST['deptcode'];
        //医生代码(选填)
        $xmlArray['doctorcode'] = $_POST['doctorcode'] == 0 ? '' : $_POST['doctorcode'];
        //开始时间(选填)
        $xmlArray['startdate'] = $_POST['startdate'];
        //结束时间(选填)
        $xmlArray['enddate'] = $_POST['enddate'];
        //交易号
        $xmlArray['functionid'] = $actionName;

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 挂号锁号(HIS004)
     */
    public function HIS004() {
        $xmlArray = Array();
        $actionName = 'HIS004';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //平台订单号
        $xmlArray['psordnum'] = $_POST['psordnum'];
        //交易号
        $xmlArray['functionid'] = ACTION_NAME;
        //应用渠道代码
        $xmlArray['syschannelcode'] = self::SYSCHANNEL_CODE;
        //应用渠道名称
        $xmlArray['syschannelname'] = self::SYSCHANNEL_NAME;
        //科室代码
        $xmlArray['deptcode'] = $_POST['deptcode'];
        //医生代码(选填)
        $xmlArray['doctorcode'] = $_POST['doctorcode'];
        //挂号序号
        $xmlArray['code'] = $_POST['code'];
        //号源日期(yyyy-mm-dd)
        $xmlArray['scheduledate'] = $_POST['scheduledate'];
        //时段(1：上午2：下午3：晚上)
        $xmlArray['timeflag'] = $_POST['timeflag'];
        //分时开始时间(选填)24hh:mi
        $xmlArray['begintime'] = $_POST['begintime'];
        //分时结束时间(选填)24hh:mi
        $xmlArray['endtime'] = $_POST['endtime'];
        //挂号费(单位：分)
        $xmlArray['regfee'] = $_POST['regfee'];
        //患者类型(1：成人2：儿童)
        $xmlArray['pattype'] = $_POST['pattype'];
        //患者姓名
        $xmlArray['patname'] = $_POST['patname'];
        //性别(m：男，f：女)
        $xmlArray['patsex'] = $_POST['patsex'];
        //患者年龄
        $xmlArray['patage'] = $_POST['patage'];
        //患者出生年月(yyyy-mm-dd)
        $xmlArray['patbirth'] = $_POST['patbirth'];
        //患者证件类型(选填)患者为儿童时，该项允许为空
        $xmlArray['patidtype'] = $_POST['patidtype'];
        //患者证件号码(选填)患者为儿童时，该项允许为空
        $xmlArray['patidno'] = $hosCode == 525009 && $xmlArray['pattype'] == 2 ? $_POST['guardidno'] : $_POST['patidno'];
        //手机号
        $xmlArray['patmobile'] = $_POST['patmobile'];
        //地址(选填)
        $xmlArray['pataddress'] = $_POST['pataddress'];
        //监护人姓名(选填)患者为儿童时，必须存在
        $xmlArray['guardname'] = $_POST['guardname'];
        //监护人证件类型(选填)患者为儿童时，必须存在
        $xmlArray['guardidtype'] = $_POST['guardidtype'];
        //监护人证件号码(选填)患者为儿童时，必须存在
        $xmlArray['guardidno'] = $_POST['guardidno'];

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));

        if ($response['resultcode'] == 1) {
            $response['serial_id'] = '';
        }
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 号源取消锁号(HIS005)
     */
    public function HIS005() {
        $xmlArray = Array();
        $actionName = 'HIS005';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //平台订单号
        $xmlArray['psordnum'] = $_POST['psordnum'];
        //医院订单号
        $xmlArray['hisordnum'] = $_POST['hisordnum'];
        //取消原因
        $xmlArray['cancelreason'] = $_POST['cancelreason'];
        //应用渠道代码
        $xmlArray['syschannelcode'] = self::SYSCHANNEL_CODE;
        //交易号
        $xmlArray['functionid'] = $actionName;

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 号源取消锁号(HIS011)已支付
     */
    public function HIS011() {
        $xmlArray = Array();
        $actionName = 'HIS011';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //医院订单号
        $xmlArray['hisordnum'] = $_POST['hisordnum'];
        //平台订单号
        $xmlArray['psordnum'] = $_POST['psordnum'];
        //应用渠道代码
        $xmlArray['syschannelcode'] = self::SYSCHANNEL_CODE;
        $this->logFile($actionName, 'insurance', $_POST['insurance_settlement']);
        //医保信息
        if ($_POST['insurance_settlement'] != '') {
            $insuranceSettlement = json_decode($_POST['insurance_settlement']);
            //医保就诊序号
            $xmlArray['akc190'] = $insuranceSettlement->akc190;
        } else {
            $xmlArray['akc190'] = '';
        }
        //医保信息
        if ($_POST['insurance_settlement'] != '') {
            //医保支付(1是 0否)
            $xmlArray['ybpay'] = 1;
        } else {
            //医保支付(1是 0否)
            $xmlArray['ybpay'] = 0;
        }
        //支付方式 1工行2微信3支付宝
        $xmlArray['paychannel'] = $_POST['paymode'];
        $xmlArray['paymode'] = $_POST['paymode'];
        //总费用
        $xmlArray['payamt'] = $_POST['payamt'];
        //医保信息
        if ($_POST['insurance_settlement'] != '') {
            $insuranceSettlement = json_decode($_POST['insurance_settlement']);
            //个人账户支付金额
            $xmlArray['yka065'] = $insuranceSettlement->yka065;
            //统筹基金支付金额
            $xmlArray['yka107'] = $insuranceSettlement->yka107;
            //现金支付金额
            $xmlArray['ykh012'] = $insuranceSettlement->ykh012;
            $xmlArray['trade_sn'] = $_POST['agtordnum'];
            //医保结算编号
            $xmlArray['yka103'] = $insuranceSettlement->yka103;
            $xmlArray['akb020'] = $hosCode;
        } else {

            //个人账户支付金额
            $xmlArray['yka065'] = '';
            //统筹基金支付金额
            $xmlArray['yka107'] = '';
            //现金支付金额
            $xmlArray['ykh012'] = '';
            $xmlArray['trade_sn'] = $_POST['agtordnum'];
            //医保结算编号
            $xmlArray['yka103'] = '';
            $xmlArray['akb020'] = $hosCode;
        }
        //2挂号1门诊
        $xmlArray['type'] = 2;
        //交易号
        $xmlArray['functionid'] = $actionName;

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 挂号信息查询(HIS006)
     */
    public function HIS006() {
        $xmlArray = Array();
        $actionName = 'HIS006';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //交易号
        $xmlArray['functionid'] = $actionName;
        //患者姓名
        $xmlArray['patname'] = $_POST['patname'];
        //患者身份证
        $xmlArray['patidno'] = $_POST['patidno'];
        //应用渠道代码
        $xmlArray['syschannelcode'] = self::SYSCHANNEL_CODE;

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 门诊缴费记录查询(HIS009)
     */
    public function HIS009() {
        $xmlArray = Array();
        $actionName = 'HIS009';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //姓名
        $xmlArray['aac003'] = $_POST['aac003'];
        //身份证
        $xmlArray['aac002'] = $_POST['aac002'];
        //应用渠道代码
        $xmlArray['syschannelcode'] = self::SYSCHANNEL_CODE;
        //单据状态
        $xmlArray['payflag'] = $_POST['payflag'];
        //就诊类别(0201普通门诊,0202门诊特殊病,0205公务员门诊)
        $xmlArray['aka130'] = $_POST['aka130'];
        //交易号
        $xmlArray['functionid'] = $actionName;

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 检验报告列表查询(HIS012)
     */
    public function HIS012() {
        $xmlArray = Array();
        $actionName = 'HIS012';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //交易号
        $xmlArray['functionid'] = $actionName;
        //身份证号
        $xmlArray['patidno'] = $_POST['patidno'];
        //姓名
        $xmlArray['patname'] = $_POST['patname'];
        //开始日期
        $xmlArray['begindate'] = $_POST['begindate'];
        //结束日期
        $xmlArray['enddate'] = $_POST['enddate'];

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 检验报告查询(HIS013)
     */
    public function HIS013() {
        $xmlArray = Array();
        $actionName = 'HIS013';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //交易号
        $xmlArray['functionid'] = $actionName;
        //检验id
        $xmlArray['inspectid'] = $_POST['inspectid'];
        //身份证号
        $xmlArray['patidno'] = $_POST['patidno'];
        //姓名
        $xmlArray['patname'] = $_POST['patname'];

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 查询医保信息
     * @param
     */
    function insuranceCheck(){
        $xmlArray = Array();
        $actionName = 'pt03';

        //检测是否签发
        //$this->issue($_POST['aac002']);

        $xmlArray['inidentity'] = '';
        $inbusinesscontentXmlArray = Array();
        //手机号
        $inbusinesscontentXmlArray['aae019'] = $_POST['aae019'];
        //个人编号
        $inbusinesscontentXmlArray['aac001'] = $_POST['aac001'];
        //身份证
        $inbusinesscontentXmlArray['aac002'] = $_POST['aac002'];
        //姓名
        $inbusinesscontentXmlArray['aac003'] = $_POST['aac003'];

        $xmlArray['inbusinesscontent'] = $this->array_to_xml_two($inbusinesscontentXmlArray);
        $inputArray['input'] = $this->array_to_xml_two($xmlArray);

        $dataXml =  $this->array_to_xml($inputArray, '', $actionName, 1);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if (intval($response['outidentity']['returnid']) != 0 || $response['resultcode'] == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $response['resultmessage'].'his个人编号查询失败';
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = 'success';
        $responseArray['item'] = $response['outbusinesscontent'];
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    /**
     * h5签发字符串获取
     * @param
     */
    function issueSign(){
        //ak
        $dataArray['ak'] = self::CARD_AK;
        //sk
        $dataArray['sk'] = self::CARD_SK;
        //dk数字密钥
        $dataArray['dk'] = self::CARD_DK;
        //channelNo渠道号
        $dataArray['channelNo'] = self::CARD_CHANNEL_NO;
        //发卡地区行政区划代码
        $dataArray['aab301'] = self::CARD_LOCAL_CODE;

        //回调地址
        $dataArray['asyncUrl'] = $_POST['async_url'];
        //社会保障号码
        $dataArray['aac002'] = $_POST['social_card_no'];
        //姓名
        $dataArray['aac003'] = $_POST['user_name'];
        //手机号
        $dataArray['aac067'] = $_POST['phone'];
        //历史数据标志
        $dataArray['historyFlag'] = $_POST['historyFlag'];
        //本地人脸标志(1代表启用本地人脸；0代表使用部平台人脸识别)
        $dataArray['baseFace'] = $_POST['baseFace'];
        //签发号
        $dataArray['signNo'] = $_POST['issue_num'];
        //openId
        $dataArray['openId'] = $_POST['openId'];
        //部平台订单号
        $dataArray['uniformOrderId'] = $_POST['uniformOrderId'];
        $dataArray['isWeb'] = $_POST['isWeb'];
        $dataArray['isIndep'] = $_POST['isIndep'];

        $this->logFile('issueSign', 'res', json_encode($dataArray, JSON_UNESCAPED_UNICODE));
        $response = $this->curlPost(self::$environmentConfig[self::ENVIRONMENT]['his_url'] . 'issue', $dataArray);
        $this->logFile('issueSigns', 'res', $response);
        if ($response == false) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = '接口地址404';
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseJson = json_decode($response);
        if ($responseJson->resultcode == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $responseJson->resultmessage;
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = $responseJson->resultmessage;
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    /**
     * h5电子社保卡解密
     * @param
     */
    function issueDecrypt(){
        //dk数字密钥
        $dataArray['dk'] = self::CARD_DK;
        //解密字符串
        $dataArray['security'] = $_POST['security'];

        $insuranceCardNo = '';
        if (isset($_POST['type']) && $_POST['type'] == 1) {
            //签发,查询社保卡号
            $userInfo = $this->pt03($_POST['social_card_no'], $_POST['user_name'], 1);
            if ($userInfo['resultcode'] == 0) {
                $responseArray['resultcode'] = 0;
                $responseArray['resultmessage'] = $userInfo['resultmessage'];
                echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
            }
            $insuranceCardNo = $userInfo['aaz500'];
        }

        $this->logFile('issueDecrypt', 'res', json_encode($dataArray, JSON_UNESCAPED_UNICODE));
        $response = $this->curlPost(self::$environmentConfig[self::ENVIRONMENT]['his_url'] . 'decrypt', $dataArray);
        $this->logFile('issueDecrypts', 'res', $response);
        if ($response == false) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = '接口地址404';
            return $responseArray;
        }
        $responseJson = json_decode($response);
        if ($responseJson->resultcode == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $responseJson->resultmessage;
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }

        $responseArrays['resultcode'] = 1;
        $responseArrays['resultmessage'] = $insuranceCardNo;
        $response = json_decode($responseJson->resultmessage);
        if ($insuranceCardNo != '') {
            $response->insuranceCardNo = $insuranceCardNo;
        }
        $responseArrays['item'] = $response;
        echo json_encode($responseArrays, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 身份识别(查询个人编号)
     * @param
     */
    function pt03($userCardNo, $userName, $full=0){
        $xmlArray = Array();
        $actionName = 'pt03';
        $xmlArray['inidentity'] = '';

        $inbusinesscontentXmlArray = Array();
        //手机号
        $inbusinesscontentXmlArray['aae019'] = '';
        //个人编号
        $inbusinesscontentXmlArray['aac001'] = '';
        //身份证
        $inbusinesscontentXmlArray['aac002'] = $userCardNo;
        //姓名
        $inbusinesscontentXmlArray['aac003'] = $userName;

        $xmlArray['inbusinesscontent'] = $this->array_to_xml_two($inbusinesscontentXmlArray);
        $inputArray['input'] = $this->array_to_xml_two($xmlArray);

        $dataXml =  $this->array_to_xml($inputArray, '', $actionName, 1);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));

        if (intval($response['outidentity']['returnid']) != 0 || $response['resultcode'] == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $response['resultmessage'].'his个人编号查询失败';
            return $responseArray;exit();
        }

        if ($full == 2) {
            $response['resultcode'] = 1;
            return $response;
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = $response['outbusinesscontent']['aac001'];
        if ($full == 1) {
            $responseArray['aaz500'] = $response['outbusinesscontent']['aaz500'];
        }
        return $responseArray;
    }

    /**
     * 预结算
     * @param
     */
    function payinsuranceUnifiedorder(){
        $xmlArray = Array();
        $actionName = 'pt04';

        $userInfo = $this->pt03($_POST['user_card_no'], $_POST['user_name']);
        if ($userInfo['resultcode'] == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $userInfo['resultmessage'];
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $aac001 = $userInfo['resultmessage'];
        $responseArray = array();

        $inidentityXmlArray = Array();
        //医院编号
        $inidentityXmlArray['akb020'] = $_POST['hospital_code_id'];
        //交易验证码
        $inidentityXmlArray['yke014'] = $actionName;
        //渠道号
        $inidentityXmlArray['channel_id'] = self::SYSCHANNEL_CODE;
        //结算类型,1为挂号2为门诊
        $inidentityXmlArray['pay_type'] = $_POST['pay_type'];
        //医院订单号
        $inidentityXmlArray['order_no'] = $_POST['hospital_order_no'];
        //平台订单号
        //$xmlArray['ssp_order_no'] = $_POST['ssp_order_no'];
        //app_id
        $inidentityXmlArray['appid'] = $_POST['app_id'];
        //来源
        $inidentityXmlArray['ly'] = self::SYSCHANNEL_NAME;
        $inidentityXmlArray['lx'] = $_POST['pay_type'];
        //生成inidentity里面的
        $inidentityXml = $this->array_to_xml_two($inidentityXmlArray);
        $xmlArray['inidentity'] = $inidentityXml;

        $inbusinesscontentXmlArray = Array();
        //个人编号
        $inbusinesscontentXmlArray['aac001'] = $aac001;
        //身份证
        $inbusinesscontentXmlArray['aac002'] = $_POST['user_card_no'];
        //社保卡号
        //$xmlArray['social_card_no'] = $_POST['social_card_no'];
        //就诊类别:aka130区分公务员门诊（0205）还是普通门诊（0201），药店购药（0101）
        $inbusinesscontentXmlArray['aka130'] = '0201';
        //明细总额
        $inbusinesscontentXmlArray['yka055'] = $_POST['total_amount'];
        //医疗统筹支付金额
        //$xmlArray['org_amount'] = $_POST['org_amount'];
        //个人账户支付金额
        //$xmlArray['self_insurance_amount'] = $_POST['self_insurance_amount'];
        //本次门诊明细行数
        $inbusinesscontentXmlArray['nums'] = $_POST['nums'];
        //发票号
        $inbusinesscontentXmlArray['yka110'] = $_POST['yka110'] != '' ? $_POST['yka110'] : 0;
        //结算日期
        $inbusinesscontentXmlArray['akc194'] = date('YmdHis', time());
        //外购标志
        $inbusinesscontentXmlArray['yke300'] = $_POST['yke300'];
        //外购时间
        $inbusinesscontentXmlArray['yke301'] = $_POST['yke301'];

        $rowXmlArray = Array();
        //记账流水号
        $rowXmlArray['yka105'] = $_POST['ssp_order_no'];
        //医保项目编码
        $rowXmlArray['yka094'] = self::INSURANCE_NO;
        //医院项目名称(诊疗项目)
        $yka095 = '自助挂号';
        if ($_POST['pay_type'] == 2) {
            $yka095 = '门诊缴费';
        }
        $rowXmlArray['yka095'] = $yka095;
        ///数量
        $rowXmlArray['akc226'] = 1;
        //单价
        $rowXmlArray['akc225'] = $_POST['total_amount'];
        //费用总额
        $rowXmlArray['yka055'] = $_POST['total_amount'];
        //医院审核标志
        $rowXmlArray['yke186'] = $_POST['yke186'];
        //开单科室编码1
        $rowXmlArray['yka097'] = $_POST['yka097'];
        //开单科室名称1
        $rowXmlArray['yka098'] = $_POST['yka098'];
        //开单医生1
        $rowXmlArray['yka099'] = $_POST['yka099'];
        //受单科室编码1
        $rowXmlArray['yka100'] = $_POST['yka100'];
        //受单科室名称1
        $rowXmlArray['yka101'] = $_POST['yka101'];
        //受单医生1
        $rowXmlArray['yka102'] = $_POST['yka102'];
        //经办人姓名1
        $rowXmlArray['aae011'] = $_POST['aae011'];
        $rowXmlArray['aae036'] = date('Y-m-d H:i:s', time());
        $rowXmlArray['yke123'] = date('Y-m-d H:i:s', time());
        //医嘱记录序号1
        $rowXmlArray['yke112'] = $_POST['yke112'];
        //备注1
        $rowXmlArray['aae013'] = $_POST['aae013'];
        //处方号
        $rowXmlArray['yke134'] = $_POST['yke134'];
        //规格(数字)
        $rowXmlArray['aka074'] = $_POST['aka074'];
        //用法(数字)
        $rowXmlArray['aka073'] = $_POST['aka073'];
        //用量(数字)
        $rowXmlArray['yka293'] = $_POST['yka293'];
        //病种编码
        $rowXmlArray['yka026'] = $_POST['yka026'];
        $rowArray['row'] = $this->array_to_xml_two($rowXmlArray);
        $inbusinesscontentXmlArray['datarow'] = $this->array_to_xml_two($rowArray);
        $xmlArray['inbusinesscontent'] = $this->array_to_xml_two($inbusinesscontentXmlArray);
        $inputArray['input'] = $this->array_to_xml_two($xmlArray);

        $dataXml =  $this->array_to_xml($inputArray, '', $actionName, 1);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if (intval($response['outidentity']['returnid']) != 0 || $response['resultcode'] == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = isset($response['outidentity']['returnmsg']) ? $response['outidentity']['returnmsg'] : $response['resultmessage'].'his提示信息无';
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = '成功';
        $responseArray['item'] = $response['outbusinesscontent'];
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 结算
     * @param
     */
    function payinsuranceSettlement(){
        $xmlArray = Array();
        $actionName = 'pt05';

        $password = $this->passwordSubstr($_POST['password']);
        //密码检测
        $this->passwordChecks($_POST['user_card_no'], $password);
        //查询个人编号
        $userInfo = $this->pt03($_POST['user_card_no'], $_POST['user_name']);
        if ($userInfo['resultcode'] == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $userInfo['resultmessage'];
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $aac001 = $userInfo['resultmessage'];

        $responseArray = array();
        $inidentityXmlArray = Array();
        //医院编号
        $inidentityXmlArray['akb020'] = $_POST['hospital_code_id'];
        //交易验证码
        $inidentityXmlArray['yke014'] = $actionName;
        //交易流水号
        $inidentityXmlArray['jylsh'] = $_POST['ssp_order_no'];
        //渠道号
        $inidentityXmlArray['channel_id'] = self::SYSCHANNEL_CODE;
        //医院订单号
        $inidentityXmlArray['order_no'] = $_POST['hospital_order_no'];
        //app_id
        $inidentityXmlArray['appid'] = $_POST['app_id'];
        //来源
        $inidentityXmlArray['ly'] = self::SYSCHANNEL_NAME;
        $inidentityXmlArray['lx'] = $_POST['order_type'];
        //生成inidentity里面的
        $inidentityXml = $this->array_to_xml_two($inidentityXmlArray);
        $xmlArray['inidentity'] = $inidentityXml;

        $inbusinesscontentXmlArray = Array();
        //顺序号
        $inbusinesscontentXmlArray['sxh'] = $_POST['sxh'];
        //个人编号
        $inbusinesscontentXmlArray['aac001'] = $aac001;
        //身份证
        $inbusinesscontentXmlArray['aac002'] = $_POST['user_card_no'];
        //社保卡号
        //$xmlArray['social_card_no'] = $_POST['social_card_no'];
        //就诊类别:aka130区分公务员门诊（0205）还是普通门诊（0201），药店购药（0101）
        $inbusinesscontentXmlArray['aka130'] = '0201';
        //明细总额
        $inbusinesscontentXmlArray['yka055'] = $_POST['total_amount'];
        //医疗统筹支付金额
        //$xmlArray['org_amount'] = $_POST['org_amount'];
        //个人账户支付金额
        //$xmlArray['self_insurance_amount'] = $_POST['self_insurance_amount'];
        //本次门诊明细行数
        $inbusinesscontentXmlArray['nums'] = $_POST['nums'];
        //发票号
        $inbusinesscontentXmlArray['yka110'] = $_POST['yka110'] != '' ? $_POST['yka110'] : 0;
        //结算日期
        $inbusinesscontentXmlArray['akc194'] = date('YmdHis', time());
        //外购标志
        $inbusinesscontentXmlArray['yke300'] = $_POST['yke300'];
        //外购时间
        $inbusinesscontentXmlArray['yke301'] = $_POST['yke301'];
        //个人账户支付金额
        $inbusinesscontentXmlArray['akc102'] = $_POST['self_insurance_amount'];

        $rowXmlArray = Array();
        //记账流水号
        $rowXmlArray['yka105'] = $_POST['ssp_order_no'];
        //医保项目编码
        $rowXmlArray['yka094'] = self::INSURANCE_NO;
        //医院项目名称(诊疗项目)
        $yka095 = '自助挂号';
        if ($_POST['pay_type'] == 2) {
            $yka095 = '门诊缴费';
        }
        $rowXmlArray['yka095'] = $yka095;
        ///数量
        $rowXmlArray['akc226'] = 1;
        //单价
        $rowXmlArray['akc225'] = $_POST['total_amount'];
        //费用总额
        $rowXmlArray['yka055'] = $_POST['total_amount'];
        //医院审核标志
        $rowXmlArray['yke186'] = $_POST['yke186'];
        //开单科室编码1
        $rowXmlArray['yka097'] = $_POST['yka097'];
        //开单科室名称1
        $rowXmlArray['yka098'] = $_POST['yka098'];
        //开单医生1
        $rowXmlArray['yka099'] = $_POST['yka099'];
        //受单科室编码1
        $rowXmlArray['yka100'] = $_POST['yka100'];
        //受单科室名称1
        $rowXmlArray['yka101'] = $_POST['yka101'];
        //受单医生1
        $rowXmlArray['yka102'] = $_POST['yka102'];
        //经办人姓名1
        $rowXmlArray['aae011'] = $_POST['aae011'];
        $rowXmlArray['aae036'] = date('Y-m-d H:i:s', time());
        $rowXmlArray['yke123'] = date('Y-m-d H:i:s', time());
        //医嘱记录序号1
        $rowXmlArray['yke112'] = $_POST['yke112'];
        //备注1
        $rowXmlArray['aae013'] = $_POST['aae013'];
        //处方号
        $rowXmlArray['yke134'] = $_POST['yke134'];
        //规格(数字)
        $rowXmlArray['aka074'] = $_POST['aka074'];
        //用法(数字)
        $rowXmlArray['aka073'] = $_POST['aka073'];
        //用量(数字)
        $rowXmlArray['yka293'] = $_POST['yka293'];
        //病种编码
        $rowXmlArray['yka026'] = $_POST['yka026'];
        $rowArray['row'] = $this->array_to_xml_two($rowXmlArray);
        $inbusinesscontentXmlArray['datarow'] = $this->array_to_xml_two($rowArray);
        $xmlArray['inbusinesscontent'] = $this->array_to_xml_two($inbusinesscontentXmlArray);
        $inputArray['input'] = $this->array_to_xml_two($xmlArray);

        $dataXml =  $this->array_to_xml($inputArray, '', $actionName, 1);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        $responseArray = array();
        if (intval($response['outidentity']['returnid']) != 0 || $response['resultcode'] == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = isset($response['outidentity']['returnmsg']) ? $response['outidentity']['returnmsg'] : $response['resultmessage'].'his提示信息无';
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = '成功';
        $responseArray['item'] = $response['outbusinesscontent'];
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 支付通知(HIS008)
     */
    public function HIS008() {
        $xmlArray = Array();
        $actionName = 'HIS008';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //交易号
        $xmlArray['functionid'] = $actionName;
        //订单支付结(SUCCESS支付成功,FAILURE支付失败)
        $xmlArray['order_pay_result'] = $_POST['order_pay_result'];
        $xmlArray['order_pay_result'] = 'SUCCESS';
        //交易流水号
        $xmlArray['trade_sn'] = $_POST['trade_sn'];
        //his订单编号
        $xmlArray['hisOrderId'] = $_POST['hisOrderId'];
        //支付金额
        $xmlArray['order_money'] = $_POST['order_money'];
        //订单处理时间
        $xmlArray['order_handle_time'] = $_POST['order_handle_time'];
        //消费类型(12 门诊13 住院14 预交金15 药店购药91 挂号)
        $type = 91;
        if ($_POST['costtype'] == 2) {
            $type = 12;
        }
        $xmlArray['consume_type'] = $type;

        //业务订单号
        if ($hosCode == 525009) {
            $xmlArray['busiorderno'] = $_POST['trade_sn'];
        } else {
            $xmlArray['busiorderno'] = $_POST['busiorderno'];
        }
        //费用类型
        $xmlArray['costtype'] = $type;
        //应用渠道代码
        $xmlArray['syschannelcode'] = self::SYSCHANNEL_CODE;
        //应用渠道名称
        $xmlArray['syschannelname'] = self::SYSCHANNEL_NAME;
        //支付渠道(1工行,2微信,3支付宝)
        $xmlArray['paychannel'] = 2;
        //支付方式(2微信,3支付宝)
        $xmlArray['paymode'] = 2;

        $this->logFile($actionName, 'insurance', $_POST['insurance_settlement']);
        //医保信息
        if ($_POST['insurance_settlement'] != '') {
            $insuranceSettlement = $this->array_to_xml_two(json_decode($_POST['insurance_settlement']));
            $xmlArray['consume_content'] = str_replace("Array", "", $insuranceSettlement);
            //医保支付(1是 0否)
            $xmlArray['ybpay'] = 1;
        } else {
            //医保支付(1是 0否)
            $xmlArray['ybpay'] = 0;
        }

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 平台支付密码检测(是否有设置过密码)
     * @param
     */
    function passwordCheck(){
        $xmlArray = Array();
        $actionName = self::BUS_CODE[2];

        //第三方id
        $idCard = $_POST['idCard'];

        $dataXml = '<?xml version="1.0" encoding="UTF-8"?><data><idCard>'.$idCard.'</idCard></data>';
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 2, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if ($response['resultcode'] == 1) {
            $response['resultcode'] = '1';
            $response['resultmessage'] = '检测成功';
        } else {
            $response['resultmessage'] = $response['resultmessage'] != '' ? $response['resultmessage'] : 'his检测失败';
        }
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 平台支付密码设置
     * @param
     */
    function passwordSetting(){
        $xmlArray = Array();
        $actionName = self::BUS_CODE[3];

        //第三方id
        $idCard = $_POST['idCard'];
        //密码
        $password = $this->passwordSubstr($_POST['password']);

        $dataXml = '<?xml version="1.0" encoding="UTF-8"?><data><thirdFlag>I101</thirdFlag><idCard>'.$idCard.'</idCard><password>'.$password.'</password></data>';
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 3, 1, $idCard, $password, 'set');
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if ($response['resultcode'] == 1) {
            $response['resultcode'] = '1';
            $response['resultmessage'] = '设置成功';
        } else {
            $response['resultmessage'] = 'his设置失败';
        }
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 平台支付密码校验(检测密码输入的对不对)
     * @param
     */
    function passwordChecks($idCard, $password){
        $xmlArray = Array();
        $actionName = self::BUS_CODE[4];

        $dataXml = '<?xml version="1.0" encoding="UTF-8"?><data><idCard>'.$idCard.'</idCard><password>'.$password.'</password></data>';
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 4, 1, $idCard, $password);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if ($response['resultcode'] != 1) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = '支付密码校验失败';
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
    }

    /**
     * 是否签发社保卡
     * @param
     */
    function issue($idCard){
        $xmlArray = Array();
        $actionName = self::BUS_CODE[5];

        $dataXml = '<?xml version="1.0" encoding="UTF-8"?><data><idCard>'.$idCard.'</idCard></data>';
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 2, 1);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if ($response['status'] != 1) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = 'his未签发';
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
    }

    /**
     * 获取/验证手机号码
     * @param
     */
    function phoneVerify(){
        $xmlArray = Array();
        $actionName = 'HIS023';

        //第三方id
        $xmlArray['user_id'] = self::TCYL_KEY . $_POST['user_id'];
        //社保卡号
        $xmlArray['social_card_no'] = $_POST['user_card_no'];
        //手机号(为空获取手机号,不为空校验手机号)
        $xmlArray['telphone'] = $_POST['phone'];
        $xmlArray['telphone'] = '';
        //appid
        $xmlArray['appid'] = $_POST['app_id'];
        $userxml['user'] = $this->array_to_xml_two($xmlArray);
        $inputxml['inputxml'] = $this->array_to_xml_two($userxml);
        $inputxmls['inputxml'] = $this->array_to_xml_two($inputxml);
        $input['input'] = $this->array_to_xml_two($inputxmls);

        $dataXml =  $this->array_to_xml($input, '', $actionName, 1);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 1, 0);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        if ($response['code'] != 'NOERROR') {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $response['resultmessage'] != '' ? $response['resultmessage'] : '手机号信息查询失败';
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = '';
        $responseArray['output']['telphone'] = $response['output']['telphone'];
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 医保退款
     * @param
     */
    function payinsuranceRefund(){
        $xmlArray = Array();
        $actionName = 'pt06';

        $userInfo = $this->pt03($_POST['user_card_no'], $_POST['user_name']);
        if ($userInfo['resultcode'] == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = $userInfo['resultmessage'];
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $aac001 = $userInfo['resultmessage'];

        //医院编号
        $inidentityXmlArray['akb020'] = $_POST['hospital_code_id'];
        //交易验证码
        $inidentityXmlArray['yke014'] = 'pt04';
        //回退交易流水号
        $inidentityXmlArray['jylsh'] = $_POST['ssp_order_no'];
        //渠道号
        $inidentityXmlArray['channel_id'] = self::SYSCHANNEL_CODE;
        //医院订单号
        $inidentityXmlArray['order_no'] = $_POST['hospital_order_no'];
        $inputArray['inidentity'] = $this->array_to_xml_two($inidentityXmlArray);

        //就诊编号
        $inbusinesscontentXmlArray['akc190'] = $_POST['akc190'];
        //结算编号
        $inbusinesscontentXmlArray['yka103'] = $_POST['yka103'];
        //就诊类别
        $inbusinesscontentXmlArray['aka130'] = $_POST['aka130'];
        //个人编码
        $inbusinesscontentXmlArray['aac001'] = $aac001;
        //费用总额
        $inbusinesscontentXmlArray['yka055'] = $_POST['total_amount'];
        //社保基金支付总额
        $inbusinesscontentXmlArray['insurance_amount'] = $_POST['insurance_amount'];
        //个人帐户支付
        $inbusinesscontentXmlArray['selfpay_amount'] = $_POST['insurance_amount'];
        $inputArray['inbusinesscontent'] = $this->array_to_xml_two($inbusinesscontentXmlArray);
        $inputsArray['input'] = $this->array_to_xml_two($inputArray);

        $dataXml =  $this->array_to_xml($inputsArray, '', $actionName, 1);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 1, 0);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));

        $responseArray = array();
        if (intval($response['outidentity']['returnid']) != 0 || $response['resultcode'] == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = isset($response['outidentity']['returnmsg']) ? $response['outidentity']['returnmsg'] : $response['resultmessage'].'his提示信息无';
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = '成功';
        $responseArray['item'] = $response['outbusinesscontent'];
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 微信订单查询
     * @param
     */
    function weixin(){
        $xmlArray = Array();
        $actionName = 'HIS021';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //交易编号
        $xmlArray['functionid'] = $actionName;
        //医院订单号
        $xmlArray['hisordnum'] = $_POST['hospital_order_no'];
        //平台订单号
        if ($hosCode == 525009) {
            $xmlArray['psordnum'] = $_POST['ssp_order_id'];
        } else {
            $xmlArray['psordnum'] = $_POST['ssp_order_no'];
        }
        $xmlArray['syschannelcode'] = self::SYSCHANNEL_CODE;
        //支付渠道(1工行2微信3支付宝)
        $xmlArray['paychannel'] = 2;
        //现金支付方式(2、微信3、支付宝)
        $xmlArray['paymode'] =2;

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 对帐单(医院)
     * @param
     */
    function payinsuranceGetbalancebill(){
        $xmlArray = Array();
        $actionName = 'HIS902';

        //医院编号
        $hosCode = $_POST['hospital_code_id'];
        //查询时间
        $xmlArray['batch_query_date'] = $_POST['end_date'];
        //应用渠道代码
        $xmlArray['syschannelcode'] = self::SYSCHANNEL_CODE;
        //10、住院查询 11、门诊查询 12、其他 91、挂号 为空查询全部
        $xmlArray['query_type'] = '';
        //交易编号
        $xmlArray['functionid'] = $actionName;

        $dataXml =  $this->array_to_xml($xmlArray, $hosCode, $actionName);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));
        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    /**
     * 对帐单(银海)
     * @param
     */
    function payinsuranceQueryorder(){
        $xmlArray = Array();
        $actionName = 'pt19';

        //医院编号
        $inidentityXmlArray['akb020'] = $_POST['hospital_code_id'];
        //开始时间
        $inidentityXmlArray['aae030'] = $_POST['begin_time'];
        //结束时间
        $inidentityXmlArray['aae031'] = $_POST['end_time'];
        //交易流水号
        $inidentityXmlArray['jylsh'] = $_POST['ssp_order_no'];
        //渠道号
        $inidentityXmlArray['channel_id'] = self::SYSCHANNEL_CODE;
        //外部平台流水号
        $inidentityXmlArray['order_no'] = $_POST['hospital_order_no'];
        //就诊号
        $inidentityXmlArray['akc190'] = '';
        //appid
        $inidentityXmlArray['appid'] = '';
        //来源
        $inidentityXmlArray['ly'] = self::SYSCHANNEL_NAME;
        $inidentitysXmlArray['inidentity'] = $this->array_to_xml_two($inidentityXmlArray);
        $inidentitysXmlArray['inbusinesscontent'] = 'inbusinesscontent';
        $inputXmlArray['input'] = $this->array_to_xml_two($inidentitysXmlArray);

        $dataXml =  $this->array_to_xml($inputXmlArray, '', $actionName, 1);
        $this->logFile($actionName, 'xml', $dataXml);

        $response = $this->hisMiddleware($dataXml, 1, 0);
        $this->logFile($actionName, 'res', $dataXml.'+'.json_encode($response, JSON_UNESCAPED_UNICODE));

        $responseArray = array();
        if (intval($response['outidentity']['returnid']) != 0 || $response['resultcode'] == 0) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = isset($response['outidentity']['returnmsg']) ? $response['outidentity']['returnmsg'] : $response['resultmessage'];
            echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);exit();
        }
        $responseArray['resultcode'] = 1;
        $responseArray['resultmessage'] = '成功';
        $responseArray['item'] = $response['outbusinesscontent'];
        echo json_encode($responseArray, JSON_UNESCAPED_UNICODE);
    }

    /**
     * hist中间件
     */
    public function hisMiddleware($dataXml, $busCode = 0, $sysCode = 0, $idCard='', $password='', $set='',$type=0) {
        $headXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><head><version>1.0.0</version><ref>I100012019031200000001</ref><sysCode>".self::SYS_CODE[$sysCode]."</sysCode><busCode>".self::BUS_CODE[$busCode]."</busCode><tradeSrc>O</tradeSrc><sender>I10001</sender><reciver>".self::SYS_CODE[$sysCode]."</reciver><date>".date('Ymd', time())."</date><time>".date('His', time())."</time><reSnd>N</reSnd><rst><tradeCode>99</tradeCode><busiCode>9999</busiCode><info></info></rst></head>";
        $dataArray['headXml'] = $headXml;
        $dataArray['bodyXml'] = $dataXml;
//        $dataArray['privateKey'] = self::WEBSERVICE_PRIVATE_KEY;
        $dataArray['privateKey'] = self::$environmentConfig[self::ENVIRONMENT]['web_service_private_key'];
//        $dataArray['webserviceUrl'] = self::WEBSERVICE_URL;
        $dataArray['webserviceUrl'] = self::$environmentConfig[self::ENVIRONMENT]['web_service_url'];
        if ($idCard != '' && $password != '') {
//            $dataArray['passwordPublicKey'] = self::PASSWORD_PUBLIC_KEY;
            $dataArray['passwordPublicKey'] = self::$environmentConfig[self::ENVIRONMENT]['password_public_key'];
            $dataArray['idCard'] = $idCard;
            $dataArray['password'] = $password;
            if ($set != '') {
                $dataArray['set'] = $set;
            }
        }
        $responseXML = $this->curlPost(self::$environmentConfig[self::ENVIRONMENT]['his_url'] . 'index', $dataArray);
        if ($responseXML == false) {
            $responseArray['resultcode'] = 0;
            $responseArray['resultmessage'] = 'web地址404';
            return $responseArray;
        }
        if ($busCode > 6) {
            $type = $busCode;
        }
        return $this->xml_to_array($responseXML,$type);
    }

    /**
     * curl post请求
     * @param $url
     * @param $data
     * @return mixed
     */
    function curlPost($url, $data){
        $ch = curl_init();
        $header = "Accept-Charset: utf-8";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        try{
            $tmpInfo = curl_exec($ch);
            $errorno=curl_errno($ch);
        } catch (Exception $e) {
            return $e.datefmt_get_error_message();
        }
        return $tmpInfo;
    }

    /**
     * array转xml
     * @param $xmlArray
     * @param $hosCode
     * @param $functionid
     * @return string
     */
    function array_to_xml($xmlArray, $hosCode, $functionid, $request=0){
        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><data>";
        if ($hosCode != '') {
            $xml .= "<hosCode>".$hosCode."</hosCode>";
        }
        $xml .= "<code>".$functionid."</code><xml><![CDATA[";
        if ($request != 1) {
            $xml .= "<Request>";
        }
        foreach ($xmlArray as $key => $val) {
            $xml .= "<".$key.">".$val."</".$key.">";
        }
        if ($request != 1) {
            $xml .= "</Request>";
        }
        $xml .= "]]></xml></data>";
        return $xml;
    }

    /**
     * array转xml(不带header)
     * @param $xmlArray
     * @param $hosCode
     * @param $functionid
     * @return string
     */
    function array_to_xml_two($xmlArray){
        $xml = "";
        foreach ($xmlArray as $key => $val) {
            $xml .= "<".$key.">".$val."</".$key.">";
        }
        return $xml;
    }

    /**
     * xml转数组
     * @param $list
     * @return mixed
     */
    public function xml_to_array($responseXML,$type=0){
        $responseXML = explode('@', $responseXML);
        $headXml = $responseXML[0];
        $responseHead = json_decode(json_encode(simplexml_load_string($headXml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        if ($responseHead['rst']['busiCode'] != '0000') {
            $responseArray['resultcode'] = 0;
            $errMsg = $responseHead['rst']['info'] != '' ? $responseHead['rst']['info'] : $responseHead['rst']['info'] . '+' . $headXml;
            $responseArray['resultmessage'] = $errMsg;
            return $responseArray;
        }

        $bodyXml = $responseXML[1];
        $responseBody = json_decode(json_encode(simplexml_load_string($bodyXml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        if (isset($responseBody['resxml'])) {
            $responseBody = json_decode(json_encode(simplexml_load_string($responseBody['resxml'], 'SimpleXMLElement', LIBXML_NOCDATA)), true);
            if ($responseBody['code'] == 1 && $type == 1) {
                $responseBody['resultcode'] = 1;
                return $responseBody;
            }
            if ((isset($responseBody['ResultCode']) && $responseBody['ResultCode'] != 0) || (isset($responseBody['resultcode']) && $responseBody['resultcode'] != 0) || (isset($responseBody['code']) && ($responseBody['code'] == 9999 || $responseBody['code'] != 'NOERROR'))) {
                $responseArray['resultcode'] = 0;
                $responseArray['resultmessage'] = isset($responseBody['message']) ? $responseBody['message'] : $responseBody['resultmessage'];
                return $responseArray;
            }
        } else {
            if ($type > 6) {
                if ($type == 8 || $type == 9) {
                    if (isset($responseBody['code']) && $responseBody['code'] != 0) {
                        $responseArray['resultcode'] = 0;
                        $responseArray['resultmessage'] = isset($responseBody['msg']) ? $responseBody['msg'] : 'wxfalse';
                        return $responseArray;
                    }
                }
            } else {
                if (isset($responseBody['status']) && $responseBody['status'] != 1) {
                    $responseArray['resultcode'] = 0;
                    $responseArray['resultmessage'] = '未设置';
                    return $responseArray;
                }
                if (isset($responseBody['code']) && $responseBody['code'] != 1) {
                    $responseArray['resultcode'] = 0;
                    $responseArray['resultmessage'] = '未设置';
                    return $responseArray;
                }
            }
        }
        //1表示成功,0表示失败
        $responseBody['resultcode'] = 1;
        return $responseBody;
    }

    /**
     * 密码截取
     * @param $password
     */
    public function passwordSubstr($password) {
        $newPassword = substr($password, 6 , strlen($password)-6);
        return substr($newPassword, 0, strlen($newPassword)-4);
    }

    /**
     * 文件保存
     * @param $action 方法名
     * @param $type 类型(xml)
     * @param $data 结果集
     */
    public function logFile($action, $type, $data) {
        $dir = "soapGetDate/" . date("Y-m-d") . "/" . $action . "/";
        $filename = date("H_i_s") . "_" . $type . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $data);
    }

    public function curl_post($url , $data=array()){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        // POST数据
        curl_setopt($ch, CURLOPT_POST, 1);
        // 把post的变量加上
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
}
